<?php
class indexController extends siteController
{
    public function index() {
        //设置分页
        $config=config('TPL');
        $size = intval($config['TPL_TEMPLATE_TAG_INDEX_PAGE']); 
        if (empty($size)) {
            $listrows = 20;
        } else {
            $listrows = $size;
        }
        $url=url('index/index',array('name'=>$tag,'page'=>'{page}'));
        $limit=$this->pageLimit($url,$listrows);

        $this->nav=array(
            0=>array('name'=>'TAG合集','curl'=>url('index/index')),
            );

        $this->info=array('name'=>'TAG 列表');

        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>'TAGS 合集','keywords'=>$tag,'description'=>$tag));

        //执行查询
        $loop=model('tags')->tags_list($limit,'','click desc,');
        $count=model('tags')->count();

        if(!empty($loop)){
            $i=0;
            foreach ($loop as $key=>$value) {
                $i++;
                $list[$key]=$value;
                $list[$key]['aurl']=url('tags/index/info',array('name'=>$value['name']));
                $list[$key]['i']=$i;
            }
        }
        $this->loop=$list;

        //获取分页
        $this->page=$this->pageShow($count);
        $this->count=$count;

        $this->show($config['TPL_TEMPLATE_TAG_INDEX']);
    }


	public function info() {
        $tag=urldecode($_GET['name']);
        if(!is_utf8($tag))
        {
            $tag=auto_charset($tag,'gbk','utf-8');
        }
        
        $tag = msubstr(in($tag),0,20);

        //查找tag信息
        if(!empty($tag)){
            $info=model('tags')->info($tag);
        }else{
            $this->error404();
        }

        if(empty($info)){
            $this->error404();
        }

        //更新点击计数
        $data=array();
        $data['click'] = $info['click'] + 1;
        $data['id'] = $info['id'];
        model('tags')->edit($data);

        //设置分页
        $config=config('TPL');
        $size = intval($config['TPL_TEMPLATE_TAG_PAGE']); 
        if (empty($size)) {
            $listrows = 20;
        } else {
            $listrows = $size;
        }
        $url=url('index/info',array('name'=>$tag,'page'=>'{page}'));
        $limit=$this->pageLimit($url,$listrows);

        $this->nav=array(
            0=>array('name'=>'TAG合集','curl'=>url('index/index')),
            1=>array('name'=>$tag,'curl'=> url('index/info',array('name'=>$tag))),
            );

        //MEDIA信息
        $this->common=api('default','common_media',array('title'=>$tag.' - TAGS','keywords'=>$tag,'description'=>$tag));

        //执行查询列表
        $loop=model('tags')->content_list($info['id'],$limit);
        $count = model('tags')->content_count($info['id']);
        if(!empty($loop)){
            $i=0;
            foreach ($loop as $key=>$value) {
                $i++;
                $list[$key]=$value;
                $list[$key]['aurl']=api('content','content_aurl',$value['aid']);
                $list[$key]['i']=$i;
            }
        }
        $this->loop=$list;
        //获取分页
        $this->page=$this->pageShow($count);
        $this->count=$count;

        $this->info=$info;
		$this->show($config['TPL_TEMPLATE_TAG']);
	}
	

	

}